package middleware

import (
	"2207a/bawei/api/internal/types"
	"2207a/bawei/api/pkg"
	"fmt"
	"github.com/zeromicro/go-zero/rest/httpx"
	"net/http"
)

type AuthTokenMiddleware struct {
}

func NewAuthTokenMiddleware() *AuthTokenMiddleware {
	return &AuthTokenMiddleware{}
}

func (m *AuthTokenMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// TODO generate middleware implement function, delete after code implementation
		fmt.Println("触发中间件")
		token, err := pkg.GetJwtToken("token")
		if err != nil {
			resp := &types.Response{
				Code:    -1,
				Message: "token 为空",
				Data:    nil,
			}
			httpx.OkJsonCtx(r.Context(), w, resp)
			return
		}
		fmt.Println(
			token)
		// Passthrough to next handler if need
		next(w, r)
	}
}
